<?php
namespace app\model;

use app\common\model\_Base;

class Image extends _Base
{
    /**
     * 保存数据
     * @param  array $data 数据
     * @return bool       
     */
    public static function doSave($data,$id = '')
    {   
        
        $image = $id?Image::get($id):new Image;
        !empty($data['path']) && $image->path = $data['path'];
        !empty($data['belong_type']) && $image->belong_type = $data['belong_type'];
        !empty($data['user_id']) && $image->user_id = $data['user_id'];
        !empty($data['user_type']) && $image->user_type = $data['user_type'];
        $image->save();
        return false;
    }

    /**
     * 删除数据 软删除 二次真实删除
     * @param  integer $id 数据编号
     * @return bool       
     */
    public static function doDelete($id)
    {
        $config = Config::destroy($id);
        return false;
    }

    /**
     * 获取数据
     * @param  array    $cond  条件
     * @param  string   $alias 条件表别名
     * @param  integer  $page  页码
     * @param  integer  $size 每页条数
     * @return array
     */
    public static function doList($cond = [], $alias = false, $page = 1, $size = 10, $order = 'sort')
    {   
        $total = Config::where($cond)->count();
        $list = Config::where($cond)->page($page,$size)->order($order)->select();
        if(!$list->isEmpty()){
            foreach ($list as $key => &$value) {
                
                if($value['type'] == self::VALUE_TYPE_ARRAY || $value['type'] == self::VALUE_TYPE_JSON){
                    $value->value = unserialize($value->value);
                }
            }
        }
        return ['total' => $total,'list' => $list];
    }
}